import requests

# 登陆
ip = 'http://192.168.181.143:8080'

mydata = {"username": "admin", "password": "123456"}
r = requests.post(f"{ip}/login", data=mydata)

# print(r.json())
# print(r.text)
# print(r.content)
# 获取token
myJSON = r.json()
token = myJSON['Admin-Token']
print(token)
myheaders = {"Admin-Token": token}

# 新增日志
myjson = {"categoryId": "1", "content": "是", "tomorrow": "是", "question": "是",
          "batchId": "14de2e8c9c1cb0d8cba69e8bb17c3356", "sendUserIds": "", "sendDeptIds": "", "customerIds": "",
          "contactsIds": "", "businessIds": "", "contractIds": ""}
a = requests.post(f"{ip}/OaLog/addOrUpdate", json=myjson, headers=myheaders)
print(a.json())
# 获取日志列表
Ljson = {"page": 1, "limit": 5, "by": 1}
L = requests.post(f"{ip}/OaLog/queryList", json=Ljson, headers=myheaders)
# 获取logId
re = L.json()["data"]["list"][0]["logId"]
# for i in re:
#     re = i["logId"]
#     print(re)
# 修改日志
Xjson = {"logId": 6,
         "categoryId": "1",
         "content": "都是",
         "tomorrow": "撒旦",
         "question": "阿斯顿",
         "batchId": "d0a6a45725deb6a88d4d83208adf64e8",
         "sendUserIds": "",
         "sendDeptIds": "",
         "customerIds": "",
         "contactsIds": "",
         "businessIds": "",
         "contractIds": ""}
X = requests.post(f"{ip}/OaLog/addOrUpdate", json=Xjson, headers=myheaders)
# print(X.json())
# 文件上传
filedata = {"type": "img","content": "是"}
furl = r"D:\2501\apiauto\wx.jpg"
fileD = {"file": ("wx.jpg",
                  open(furl, "rb"),
                  "image/jpeg")}
S = requests.post(f"{ip}/file/upload", data=filedata, headers=myheaders, files=fileD)
# print(S.json())
#删除日志
Sdata = {"logId":re}
k = requests.post(f"{ip}/OaLog/deleteById",data=Sdata,headers=myheaders)
print(k.json())
